Skip to content
This repository was archived by the owner on Jan 21, 2026. It is now read-only.

Add more preferences for configuring openapi search paths#424

Merged
tlmii merged 2 commits intodotnet:masterfrom
tlmii:dev/more-search-path-config
Nov 2, 2020
Merged

Add more preferences for configuring openapi search paths#424
tlmii merged 2 commits intodotnet:masterfrom
tlmii:dev/more-search-path-config

Conversation

@tlmii
Copy link
Member

@tlmii tlmii commented Oct 29, 2020

Resolves #360.

Adds two additional preferences:

  • swagger.addToSearchPaths (adds the specified paths to the default list)
  • swagger.removeFromSearchPaths (removes the specified paths from the default list if they exist)

and configures the original available preference (swagger.searchPaths) to override both the default list and the two new preferences.

@tlmii tlmii requested review from bzhu94 and jimmylewis October 29, 2020 07:41
public ApiConnection(IPreferences preferences, IWritable logger, bool logVerboseMessages, IOpenApiSearchPathsProvider? openApiSearchPaths = null)
{
_preferences = preferences ?? throw new ArgumentNullException(nameof(preferences));
_ = preferences ?? throw new ArgumentNullException(nameof(preferences));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks a little funky, though I understand the intent. Maybe put the ArgumentNullException check in the ctor of OpenApiSearchPathsProvider instead where it's actually used?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming the "looks a little funky" was in reference to using the discard. According to Jimmy, it saves a few ops!

But yeah, since I also changed it to not store the value anymore and just pass it, moving it makes sense. Done.


namespace Microsoft.HttpRepl.Preferences
{
internal class OpenApiSearchPathsProvider : IOpenApiSearchPathsProvider
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: sealed?

return DefaultSearchPaths.Union(addToSearchPaths).Except(removeFromSearchPaths);
}

private static string[] Split(string searchPaths)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this function for exclusive use with search path preferences, or could it be useful for current other preferences or potential future ones down the line?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a huge fan of pipe- (or frankly anything-) delimited strings, so I'm hoping there won't be too many of those before we get to a better settings system. I believe this is the only use case right now.


namespace Microsoft.HttpRepl.Fakes
{
public class FakePreferences : IPreferences
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: sealed? :P

public FakePreferences()
{
DefaultPreferences = new Dictionary<string, string>();
_currentPreferences = new();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this madness...Can you link me to this C# feature?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

@bzhu94 bzhu94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@tlmii tlmii merged commit b537260 into dotnet:master Nov 2, 2020
@tlmii tlmii deleted the dev/more-search-path-config branch November 2, 2020 08:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make well-known Open API description locations list more easily configurable

2 participants